package cn.com.jslh.boarpro.main.presenter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;

import com.blankj.utilcode.util.SPUtils;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import cn.com.jslh.boarpro.base.BaseApplication;
import cn.com.jslh.boarpro.main.contract.AddDuanNaiContract;
import cn.com.jslh.boarpro.main.model.AddDuanNaiModelImpl;
import cn.com.jslh.boarpro.tables.DuanNaiTable;
import cn.com.jslh.boarpro.util.database.DataBaseUtil;

/**
 * Created by Administrator on 2017/10/18.
 */

public class AddDuanNaiPresenterImpl implements AddDuanNaiContract.Presenter {

    private AddDuanNaiContract.View view;
    private AddDuanNaiModelImpl addDuanNaiModel;
    private Context context;
    public AddDuanNaiPresenterImpl(AddDuanNaiContract.View view,Context context) {
        this.view = view;
        this.context = context;
        view.setPresenter(this);
        addDuanNaiModel = new AddDuanNaiModelImpl(context);
    }

    @Override
    public void start() {
        //加载猪舍
        addDuanNaiModel.loadZhuShe();
    }

    @Override
    public void bindRV(RecyclerView recyclerView) {

    }

    @Override
    public List<JSONObject> getZhuShes() {
        return addDuanNaiModel.getZhuShes();
    }

    /**
     *
     * @param muzhuID 母猪ID
     * @param muzhuErHao 母猪耳号
     * @param pinzhong 品种
     * @param ZhuShe 当前猪舍
     * @param nowZPigFlkID 当前猪群id
     * @param nowZshuqun 当前猪群
     * @param goZhuSheID 去向猪舍id
     * @param goZhushe 去向猪舍
     * @param goZPigFlkID 去向猪群ID
     * @param goZhuQun 去向猪群
     */
    @Override
    public void saveDatas(String muzhuID, String muzhuErHao, String pinzhong, String ZhuShe, String nowZPigFlkID, String nowZshuqun, String goZhuSheID, String goZhushe, String goZPigFlkID, String goZhuQun,String isWillOut) {
        DuanNaiTable duanNaiTable = new DuanNaiTable();
        duanNaiTable.setMuZhuID(muzhuID);
        duanNaiTable.setMuZhuErHao(muzhuErHao);
        duanNaiTable.setPinZhong(pinzhong);
        duanNaiTable.setDqZhuShe(ZhuShe);
        duanNaiTable.setNowZPigFlkID(nowZPigFlkID);
        duanNaiTable.setDqPigFlk(nowZshuqun);
        duanNaiTable.setGoZhuShe(goZhushe);
        duanNaiTable.setGoZhuSheID(goZhuSheID);
        duanNaiTable.setGoZPigFlk(goZhuQun);
        duanNaiTable.setGoZPigFlkID(goZPigFlkID);
        duanNaiTable.setLineID(SPUtils.getInstance().getString(BaseApplication.FLINEID));
        duanNaiTable.setIsWillOut(isWillOut);
        addDuanNaiModel.savDuanNai(duanNaiTable);
    }

    @Override
    public Boolean isHave(String erHao) {
        ArrayList<Object> datas = DataBaseUtil.GetData(context, DuanNaiTable.class, " where muZhuErHao = '" + erHao + "'");
        if(datas==null||datas.size()==0){
            return false;
        }
        return true;
    }
}
